package com.sun.memo.web.controller;

import com.sun.memo.entity.BackLog;
import com.sun.memo.entity.User;
import com.sun.memo.service.IBackLogService;
import com.sun.memo.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

/**
 * @author wys
 **/
@Controller
public class BackLogController {

    @Autowired
    private IBackLogService backLogService;

    @Autowired
    private IUserService userService;

    /**
     * 默认为：不重要、未完成、截至日期今天
    **/
    @ResponseBody
    @RequestMapping("/addLog")
    public String addLog(String content,Integer id){
        User user = userService.findUserById(id);
        BackLog backLog = new BackLog(new Date(),content, false, false,user);
        backLogService.saveBackLog(backLog);
        return "ok";
    }

    @ResponseBody
    @RequestMapping("/addImportantLog")
    public String addImportantLog(String content,Integer id){
        User user = userService.findUserById(id);
        BackLog backLog = new BackLog(new Date(),content, false, true,user);
        backLogService.saveBackLog(backLog);
        return "ok";
    }

    /**
     * 标记为完成
     **/
    @ResponseBody
    @RequestMapping("/completeLog")
    public String completeLog(Integer id){
        backLogService.signalComplete(id);
        return "ok";
    }

    /**
     * 标记重要或取消标记
     **/
    @ResponseBody
    @RequestMapping("/starLog")
    public String statLog(Integer id){
        backLogService.signalImportant(id);
        return "ok";
    }

//    /**
//     * 修改信息 页面未作
//     **/
//    @ResponseBody
//    @RequestMapping
//    public String modifyLog(){
//        return "";
//    }
//
//
//    /**
//     * 删除信息 页面未作
//     **/
//    @ResponseBody
//    @RequestMapping
//    public String deleteLog(){
//        return "";
//    }
//

}
